| Total Complexity | 2 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 6 | |||
| 7 | @QueryHandler(GetSchoolUsersQuery) |
||
| 8 | export class GetSchoolUsersQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('ISchoolUserRepository') |
||
| 11 | private readonly schoolUserRepository: ISchoolUserRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute(query: GetSchoolUsersQuery): Promise<SchoolUserView[]> { |
||
| 15 | const schoolUserViews: SchoolUserView[] = []; |
||
| 16 | const schoolUsers = await this.schoolUserRepository.findUsersBySchool(query.schoolId); |
||
| 17 | |||
| 18 | for (const schoolUser of schoolUsers) { |
||
| 19 | const user = schoolUser.getUser(); |
||
| 20 | |||
| 21 | schoolUserViews.push( |
||
| 22 | new SchoolUserView( |
||
| 23 | schoolUser.getId(), |
||
| 24 | user.getEmail(), |
||
| 25 | 'schoolUser' |
||
| 26 | ) |
||
| 27 | ); |
||
| 28 | } |
||
| 29 | |||
| 30 | return schoolUserViews; |
||
| 31 | } |
||
| 33 |